<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="../static/jquery-easyui-1.5.5.3/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="../static/jquery-easyui-1.5.5.3/themes/bootstrap/easyui.css"/>
<link rel="stylesheet" type="text/css" href="../static/jquery-easyui-1.5.5.3/themes/icon.css"/>
<script type="text/javascript" src="../static/jquery-easyui-1.5.5.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../static/jquery-easyui-1.5.5.3/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
$(function(){
	$("#username").textbox({
		width: 130,
		missingMessage:'用户名必填'
	});
	$("#name").textbox({
		width: 130,
		missingMessage:'姓名必填'
	});
	$("#remark").textbox({
		width: 130,
	});
	
	$("#t_user").datagrid({
		idField: 'id',
		title: '用户列表',
		width: '100%',
		fitColumns: true,
		striped: true,
		loadMsg: '数据正在加载...',
		rownumbers: true,
		url: 'list',
		frozenColumns: [
			[
				{     
					field: 'ck',
					width: 50,
					checkbox: true
				}
			]
		],
		columns: [
			[
				{
					field: 'id',
					title: 'id',
					width: 100,
					align: 'center'
				},{
					field: 'username',
					title: '用户名',
					width: 150,
					align: 'center'
				},{
					field: 'name',
					title: '姓名',
					width: 150,
					align: 'center'
				},{
					field: 'remark',
					title: '备注',
					width: 150,
					align: 'center'
				},{
					field: 'aaa',
					title: '操作',
					width: 150,
					align: 'center',
					formatter:add
				}
			]
		],
		pagination: true,
		pageSize: 10,
		pageList: [3, 5, 10, 20],
		toolbar: [
			{
				text:'新增用户',
				iconCls: 'icon-add',
				handler: function(){
					$('#mydialog').dialog('open');	
				}
			},{
				text: '修改用户',
				iconCls: 'icon-edit',
				handler: function(){
					var arr = $('#t_user').datagrid('getSelections');
					if(arr.length != 1){
						$.messager.show({
							title: '提示信息',
							msg: '只能选中一行记录进行修改！'
						});
					}else{
						$('#mydialog').dialog({
							title: '修改用户'
						});
						$('#mydialog').dialog('open');
						$('#myform input').val("");
						$('#myform').form('load', {  
							id:arr[0].id,
							name:arr[0].name,
							username:arr[0].username,
							password:arr[0].password,
							remark:arr[0].remark,
							lesseeAdmin:arr[0].lesseeAdmin.id
						});
					}
				}
			},{
				text: '删除用户',
				iconCls: 'icon-remove',
				handler: function(){
					var arr = $('#t_user').datagrid('getSelections');
					if(arr.length <= 0){
						$.messager.show({
							title: '提示信息',
							msg: '至少选中一行记录进行删除！'
						});
					}else{
						$.messager.confirm('提示信息', '确认删除'+arr.length+'条数据？', function(r){
							if(r){
								var ids = '';
								for(var i = 0; i < arr.length; i++){
									ids += arr[i].id + ',';
								}
								ids = ids.substring(0, ids.length-1); 
								
								$.post('delete', {ids: ids}, function(){
									$('#t_user').datagrid('reload');
									$('#t_user').datagrid('unselectAll');
									$.messager.show({
										title: '提示信息',
										msg: '操作成功！'
									});
								});
							}else{
								return ;
							}
						});
					}
				}
			}
		]
	});
	
	function add(value,row,index){
  		return "<a class='easyui-linkbutton' onclick='fun_1("+row.id+");'>重置密码</a>";
  	}
	
	
	
	$('#bin1').click(function(){
		if($('#myform').form('validate')){
			$.ajax({
				type:'post',
				url:'save',
				cache:false,
				data:$('#myform').serialize(),
				dataType:'json',
				success:function(){
					$('#mydialog').dialog('close');
					$('#t_user').datagrid('reload');
					$.messager.show({
						title:'ok',
						msg:'保存成功！'
					});
				},
			});
		}else{
			$.messager.show({
				title:'提示信息！',
				msg:'数据验证不通过，不能保存！'
			});
		}
	});
	$('#bin2').click(function(){
		$('#mydialog').dialog('close');
	});
});

function fun_1(id){
	if(confirm("你确定重置密码吗？")){
		$.post('cz', {id: id}, function(data){
			alert(data);
		});
	}
}
</script>
</head>
<body>
	<table id="t_user"></table>
	<div id="mydialog" title="新增用户" draggable=false class="easyui-dialog" closed=true>
		<form id="myform" action="invoice/add" method="post">
		<table>
				<tr>
					<input type="hidden" name = "id" value="">
					<input type="hidden" name = "password" value="">
					<input type="hidden" name = "lesseeAdmin" class="easyui-validatebox" value="">
					<td>用户名：</td>
					<td><input type="text" name = "username" id="username" class="easyui-validatebox" required=true value="" ></td>
				</tr>
				<tr>
					<td>姓名：</td>
					<td><input type="text" name = "name" id="name" class="easyui-validatebox" required=true value="" ></td>
				</tr>
				<tr>
					<td>备注：</td>
					<td><input type="text" name = "remark" id="remark" class="easyui-validatebox" value="" ></td>
				</tr>
				<td colspan="2" align="center">
					<a id="bin1" class="easyui-linkbutton">确定</a>
					<a id="bin2" class="easyui-linkbutton">关闭</a>
				</td>
		</table>
		</form>
	</div>
</body>
</html>